<!DOCTYPE html>
<html>
<head>
    <title>IPA 应用列表</title>
    <style>
        table { width: 100%; border-collapse: collapse; }
        th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
        th { background-color: #f2f2f2; }
        tr:hover { background-color: #f5f5f5; }
        .action-cell { white-space: nowrap; }
    </style>
</head>
<body>
    <h1>IPA 应用管理</h1>
    <a href="/upload">上传新应用</a>
    
    <form action="/apps" method="get" style="margin: 20px 0;">
        <input type="text" name="bundleId" placeholder="Bundle ID" value="{{.bundleId}}">
        <input type="text" name="bundleVersion" placeholder="版本号" value="{{.bundleVersion}}">
        <input type="text" name="title" placeholder="应用名称" value="{{.title}}">
        <button type="submit">搜索</button>
    </form>
    
    <table>
        <tr>
            <th>应用名称</th>
            <th>Bundle ID</th>
            <th>版本号</th>
            <th>版本标签</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        {{range .Apps}}
        <tr>
            <td>{{.Title}}</td>
            <td>{{.BundleID}}</td>
            <td>{{.BundleVersion}}</td>
            <td>{{.BundleTag}}</td>
            <td>{{formatTime .UpdatedAt}}</td>
            <td class="action-cell">
                <a href="/app/{{.ID}}" target="_blank">查看</a> |
                <a href="#" onclick="confirmDelete('{{.ID}}')">删除</a> |
		<!--<a href="/update-form/{{.ID}}">编辑</a>-->
            </td>
        </tr>
        {{end}}
    </table>
    
    <script>
        function confirmDelete(id) {
            if (confirm("确定要删除此应用吗？")) {
                fetch(`/delete/${id}`, { method: 'POST' })
                    .then(response => response.json())
                    .then(data => {
                        if (data.status === 'deleted') {
                            location.reload();
                        }
                    });
            }
        }
    </script>
</body>
</html>
